/*
 * @# JSONUtil.java 2011-12-2 下午03:44:00
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.experiments.memcached;

import java.io.UnsupportedEncodingException;

import com.ianswer.common.util.JsonBinder;

/**
 * @author lunx
 */
public class JSONUtil implements SerializerUtil {

	//本示例数据测试  581ms
	
	public byte[] serializer(Object obj) throws RuntimeException {
		JsonBinder jb = JsonBinder.buildNonNullBinder();
		try {
			return jb.toJson(obj).getBytes("UTF-8");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException("UnsupportedEncodingException", e);
		}
	}

	public <T> T unSerializer(byte[] bytes, Class<T> clazz) throws RuntimeException {
		JsonBinder jb = JsonBinder.buildNonNullBinder();
		try {
			return jb.fromJson(new String(bytes, "UTF-8"), clazz);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException("UnsupportedEncodingException", e);
		}
	}
}
